//////////////////////////////////////////////////////////////////////////////
//                                                                          //
//     Filename: ProtocolTranslator.h                                       //
//  Create date: April 1, 2004                                              //
//                                                                          //
//////////////////////////////////////////////////////////////////////////////
//                                                                          //
//  Description: This file describes the ProtocolTranslator class, which is //
//                an abstract base class that defines the generic interface //
//                for objects that translate from one protocol to another.  //
//                                                                          //
//////////////////////////////////////////////////////////////////////////////
//       Copyright (c) 2004 - Realtime Gaming.  All rights reserved.        //
//////////////////////////////////////////////////////////////////////////////

#ifndef __PROTOCOL_TRANSLATOR__
#define __PROTOCOL_TRANSLATOR__

#include "lib.h"
#include "serv.h"
#include "tracksql.h"

//////////////////////////////////////////////////////////////////////////////
// ProtocolTranslator Class
//////////////////////////////////////////////////////////////////////////////
class ProtocolTranslator
{
public:
    ProtocolTranslator( Server* pServer, Connection* pParent, uint8 nGameID, uint8 nNumBytesMsgLen );
    virtual ~ProtocolTranslator();

    // Public Interface
    virtual bool8  ParseIncomingMessage    ( uint8* pInBuff, int32* pIEat, uint8* pOutBuff, uint32 nOutBuffSize ) = 0;
    virtual bool8  HandleMessage           ( uint8* pOutBuff, uint32 nOutBuffSize, int32* pnOutBytesUsed ) = 0;
    virtual bool8  TranslateIncomingMessage( uint8* pGameInBuff,  uint32 nGameInBuffSize, uint8* pOutBuff, uint32 nOutBuffSize ) = 0;
    virtual uint32 TranslateOutgoingMessage( uint8* pOutBuff, uint32 nOutBuffSize, uint8* pGameOutBuff, uint32 nGameOutBuffSize, uint32 nTotalGameBytes ) = 0;
	virtual bool8  ReturnErrorMessage      ( const String& sError, uint8* pOutBuff, uint32 nOutBuffSize ) = 0;

    uint8 GetNumBytesMsgLen() const { return m_nNumBytesMsgLen; }
    void  SetNumBytesMsgLen( uint8 nBytes ) { m_nNumBytesMsgLen = nBytes; };
    virtual uint8 GetNumBytesRecvMsgLen() const { return m_nNumBytesMsgLen; }    // kharmon.  12-12-06.  For some games (MHVP) the send and receive msg length bytes are different.

    uint8 GetGameID() const { return m_nGameID; };
    void  SetGameID( uint8 nGameID ) { m_nGameID = nGameID; };

    bool8 UsingFunPID() const { return m_bUsingFunPID; };


    // Login Error Codes
    enum
    {
        // These are from the account server
        eTryLater = 1,
        eAcntExists = 2,
        eMissingData = 3,
        eBadPass = 4,
        eNotAllowed = 5,
        eBadVersion = 6,
        eTrackFailed = 7,
        eLoggedIn = 8,
        // These are our own
        eFunNotAvail = 50,
        eExternalAuthFailed = 51
    } eLoginErrors;

protected:
	Server* m_pServer;

public:
	PID         m_pid;
    String      m_sLogin;
	uint8       m_nMachineID;
	uint8       m_nGameID;
    uint8       m_nNumBytesMsgLen;
	bool8       m_bForFun;
	Connection* m_pParent;
    uint8       m_nLastLoginError;
    bool8       m_bUsingFunPID;
	String		m_sAuthenticationToken; // CSN-7075: New Authentication
	uint8		m_nClientID;
};

#endif //#ifndef __PROTOCOL_TRANSLATOR__